﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FiveInRow.Entity
{
    public class Strategy : IStrategy
    {
        public void NextPoint(IChessStatus chessStatus,ref int row,ref int col)
        {
            Point loc = GetRandomPoint(chessStatus);
            row = loc.X;
            col = loc.Y;
        }

        private Point GetRandomPoint(IChessStatus chessStatus)
        {
            var size = chessStatus.Rows;
            int row;
            int col;
            GenerateRandomPoint(size, out row, out col);
            while (chessStatus.HasPiece(row, col))
            {
                GenerateRandomPoint(size, out row, out col);
            }

            return new Point(row, col);
        }

        private void GenerateRandomPoint(int maxSize, out int row,out int col)
        {
            Random rand = new Random();
            row = rand.Next(0, maxSize);
            col = rand.Next(0, maxSize);
        }
    }
}
